package com.okaixz.client.controller;


import com.okaixz.client.model.domain.Goods;
import com.okaixz.client.service.IGoodsService;
import com.okaixz.common.client.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cdz
 * @since 2024-10-17
 */
@RestController
@RequestMapping("/goods")
@Api("商品相关操作")
public class GoodsController {

    @Autowired
    private IGoodsService goodsService;
    @GetMapping("/list/{type}")
    public Result<List<Goods>> getList(@PathVariable Integer type){
        List<Goods> list = goodsService.getListByType(type);
        return Result.success(list);
    }
    @GetMapping("/vip/list")
    public Result<List<Goods>> getVipList(){
        List<Goods> list = goodsService.getVipList();
        return Result.success(list);
    }
    @GetMapping("/tokens/list")
    public Result<List<Goods>> getTokensList(){
        List<Goods> list = goodsService.getTokensList();
        return Result.success(list);
    }
    @GetMapping("/{id}")
    public Result<Goods> getById(@PathVariable(required = false) Integer id){
        Goods goods = goodsService.getById(id);
        return Result.success(goods);
    }
    @ApiOperation("根据客户端名称查询商品")
    @GetMapping("/list/clientname/{clientname}")
    public Result<List<Goods>> getListByClientName(@PathVariable String clientname){
        List<Goods> list = goodsService.getListByClientName(clientname);
        return Result.success(list);
    }

}
